// pages/personal/myorder/myorder.js
var utils = require('../../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        curHdIndex: 0,
        currentPage:1,
        gostateId:1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that=this;
        that.crowdGoods(that.data.currentPage, that.data.gostateId)
    },
    //我的拼购
    crowdGoods: function (currentPage, gostateId) {
        var that = this;
        utils.showLoading();
        utils.http("/api/v1/member/my_group_order_list", { page: currentPage, gostate: gostateId}, function (res) {
            utils.hideLoading();
            var allpost = that.data.crowd;
            if (allpost == undefined) {
                allpost = [];
            }
            for (var i in res.datas) {
                allpost.push(res.datas[i]);
            }
            if (res.datas.length < 10) {
                that.setData({
                    tishi_title: '已加载全部',
                });
            } else {
                that.setData({
                    tishi_title: '加载更多',
                });
            }
            that.setData({
                crowd: allpost,
                ready: res.datas.length == 0 ? 1 : 2,
            })
        })
    },
    /**
* 页面上拉触底事件的处理函数
*/
    onReachBottom: function () {
        var that = this;
        if (that.data.ready == 2) {
            var page = that.data.currentPage + 1
            that.setData({
                currentPage: page,
            })
            that.crowdGoods(page, that.data.gostateId);
        }

    },
    //tab切换
    tab: function (e) {
        var that=this;
        var gostateId = e.currentTarget.dataset.id;
        var dataId = e.currentTarget.id;
        var curHdIndex = dataId;
        this.setData({
            curHdIndex: curHdIndex,
            gostateId: gostateId,
            currentPage:1,
            crowd:[]

        })
        that.crowdGoods(that.data.currentPage, that.data.gostateId)
    },
    //订单详情
    onOrderDetailsTap: function (e) {
        console.log(e);
        wx.navigateTo({
            url: '../myorderdetails/myorderdetails?id='+e.currentTarget.dataset.id,
        })
    },
    //继续拼单
    onEvaluationTap: function (e) {
        wx.navigateTo({
            url: '../../allssembledetails/allssembledetails?id=' + e.currentTarget.dataset.id
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})